#!/bin/bash

#Copyright (c) 2025, Alibaba Cloud and its affiliates;
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at

#   http://www.apache.org/licenses/LICENSE-2.0

#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.

INSTALL_ROOT=`pwd`
FCE_CONF=$INSTALL_ROOT/config/fce_server.conf
function readINI() {
    conf=$1
    key=$2
    var=$(grep -i "${key}=" ${conf} | sed -E 's/[ "\t]//g' | awk -F= '{print $2}')
    echo ${var}
}

# 自认证
#openssl req -newkey rsa:2048 -nodes -keyout ${INSTALL_ROOT}/config/server.key -x509 -days 365 -out ${INSTALL_ROOT}/config/server.crt <<EOF
#EOF

# init db
if [ -r ${INSTALL_ROOT}/sqlite.db ]
then
/usr/bin/sqlite3 ${INSTALL_ROOT}/sqlite.db <<EOF
drop table if exists vncinfo;
EOF
fi

bash ${INSTALL_ROOT}/scripts/start_server_service.sh $1
bash ${INSTALL_ROOT}/scripts/health.sh start